package core.security;

import java.util.ArrayList;
import java.util.Collection;

import model.security.UsrUser;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UserDetails;

import dao.security.UsrUserDao;

public class MyUserDetailService implements UserDetailsService{
	private UsrUserDao usrUsersDao;
	
	public UserDetails loadUserByUsername(String username){
		Collection<GrantedAuthority> auths=new ArrayList<GrantedAuthority>();

		//得到用户的权限
		auths = usrUsersDao.getUserAuthByName(username);
		UsrUser user=usrUsersDao.findOne("useraccount", username);
	
		return new UsrUser(user.getUseraccount(),
				user.getUserpassword(),user.getUserdesc(),user.getEnabled(),user.getIsadmin(),
				user.getCreatetime(),user.getRealname(),user.getNickname(),user.getPhone(),user.getFax(),
				user.getAddress(),user.getZip(),user.getPhoto(),user.getUsrUserRoles(),true, true, true,auths);
	}

	public UsrUserDao getUsrUsersDao() {
		return usrUsersDao;
	}

	public void setUsrUsersDao(UsrUserDao usrUsersDao) {
		this.usrUsersDao = usrUsersDao;
	}


	
}
